package D12_6z.反射_4;

import java.lang.reflect.Constructor;

public class Demo1 {
    /**
     * 方法功能:新建实例对象
     * @param //className 包名+类名
     * @param args 构造函数的参数
     * @return 新建的实例对象
     */
    public static void main(String[] args) throws Exception {
        Object[] arr = {"小明",20};
        System.out.println(new Demo1().newInstance("Y2019.M12_.D12_6z.反射_4.Person",arr));
    }
    public Object newInstance (String className, Object[] args) throws Exception{
        Class<?> aClass = Class.forName(className);
        Constructor<?> constructor = aClass.getConstructor(String.class, int.class);
        Object o = constructor.newInstance(args);
        return o;
    }
}
